package com.itita.ww2.game.alliance.event;

import java.util.Iterator;
import java.util.Vector;

import com.itita.ww2.game.alliance.event.IAllianceMemberJoinListener.JoinType;
import com.itita.ww2.game.alliance.event.IAllianceMemberRoleChangedListener.ChangedType;
import com.itita.ww2.game.enums.ContributeType;
import com.itita.ww2.game.enums.StateEnum;
import com.itita.ww2.model.user.UserProfile;
import com.itita.ww2.puredb.model.Alliance;
import com.itita.ww2.puredb.model.AllianceMember;
import com.itita.ww2.puredb.model.AllianceUserQuitCD;
import com.smartfoxserver.v2.entities.data.ISFSObject;

public class AllianceEventDispatch {

	private static Vector<IAllianceDisbandListener> m_DisbandListeners = new Vector<>();
	private static Vector<IAllianceTranferListener> m_TranferListeners = new Vector<>();
	private static Vector<IAllianceMemberRemovedListener> m_MemberRemovedListeners = new Vector<>();
	private static Vector<IAllianceMemberJoinListener> m_MemberJoinListeners = new Vector<>();
	private static Vector<IAllianceMemberRoleChangedListener> m_MemberRoleChangedListeners = new Vector<>();
	private static Vector<IAllianceInfoUpdateListener> m_AllianceInfoUpdateListeners = new Vector<>();
	private static Vector<IAllianceRejectJoinListener> m_AllianceRejectJoinListeners = new Vector<>();
	private static Vector<IAllianceUpgradeListener> m_AllianceUpgradeListeners = new Vector<>();
	private static Vector<IAllianceContributionChangedListener> m_ContributionChangedListeners = new Vector<>();

	public static void addListener(IAllianceContributionChangedListener listener) {
		m_ContributionChangedListeners.add(listener);
	}

	public static void addListener(IAllianceDisbandListener listener) {
		m_DisbandListeners.add(listener);
	}

	public static void addListener(IAllianceTranferListener listener) {
		m_TranferListeners.add(listener);
	}

	public static void addListener(IAllianceMemberRemovedListener listener) {
		m_MemberRemovedListeners.add(listener);
	}

	public static void addListener(IAllianceMemberJoinListener listener) {
		m_MemberJoinListeners.add(listener);
	}

	public static void addListener(IAllianceInfoUpdateListener listener) {
		m_AllianceInfoUpdateListeners.add(listener);
	}

	public static void addListener(IAllianceMemberRoleChangedListener listener) {
		m_MemberRoleChangedListeners.add(listener);
	}

	public static void addListener(IAllianceRejectJoinListener listener) {
		m_AllianceRejectJoinListeners.add(listener);
	}

	public static void addListener(IAllianceUpgradeListener listener) {
		m_AllianceUpgradeListeners.add(listener);
	}

	public static void onAllianceContributionChanged(UserProfile userProfile, Alliance alliance, int changedAmount,
			ContributeType type) {
		for (Iterator<IAllianceContributionChangedListener> iter = m_ContributionChangedListeners.iterator(); iter
				.hasNext();) {
			iter.next().onAllianceContributionChanged(userProfile, alliance, changedAmount, type);
		}
	}

	public static void onAllianceUpgrade(Alliance alliance) {
		for (Iterator<IAllianceUpgradeListener> iter = m_AllianceUpgradeListeners.iterator(); iter.hasNext();) {
			iter.next().onAllianceUpgrade(alliance);
		}
	}

	public static void onAllianceDisband(Alliance alliance, StateEnum state) {
		for (Iterator<IAllianceDisbandListener> iter = m_DisbandListeners.iterator(); iter.hasNext();) {
			iter.next().onAllianceDisband(alliance, state);
		}
	}

	public static void onAllianceTransfer(UserProfile source, UserProfile target, AllianceMember sourceMember,
			AllianceMember targetMember, Alliance alliance, StateEnum state) {
		for (Iterator<IAllianceTranferListener> iter = m_TranferListeners.iterator(); iter.hasNext();) {
			iter.next().onAllianceTransfer(source, target, sourceMember, targetMember, alliance, state);
		}
	}

	public static void onAllianceInfoUpdate(Alliance alliance, ISFSObject changedParams) {
		for (Iterator<IAllianceInfoUpdateListener> iter = m_AllianceInfoUpdateListeners.iterator(); iter.hasNext();) {
			iter.next().onAllianceInfoUpdate(alliance, changedParams);
		}
	}

	public static void onAllianceMemberRemoved(UserProfile source, UserProfile target, Alliance alliance,
			AllianceMember allianceMember, AllianceUserQuitCD allianceUserQuitCD, boolean isKicked) {
		for (Iterator<IAllianceMemberRemovedListener> iter = m_MemberRemovedListeners.iterator(); iter.hasNext();) {
			iter.next().onAllianceMemberRemoved(source, target, alliance, allianceMember, allianceUserQuitCD, isKicked);
		}
	}

	public static void onAllianceMemberJoin(UserProfile source, UserProfile target, Alliance alliance,
			AllianceMember allianceMember, JoinType joinType) {
		for (Iterator<IAllianceMemberJoinListener> iter = m_MemberJoinListeners.iterator(); iter.hasNext();) {
			iter.next().onAllianceMemberJoin(source, target, alliance, allianceMember, joinType);
		}
	}

	public static void onAllianceRejectJoin(UserProfile source, UserProfile target, Alliance alliance,
			AllianceMember allianceMember) {
		for (Iterator<IAllianceRejectJoinListener> iter = m_AllianceRejectJoinListeners.iterator(); iter.hasNext();) {
			iter.next().onRejectJoin(source, target, alliance, allianceMember);
		}
	}

	public static void onAllianceMemberRoleChanged(UserProfile source, UserProfile target,
			AllianceMember allianceMember, ChangedType changedType) {
		for (Iterator<IAllianceMemberRoleChangedListener> iter = m_MemberRoleChangedListeners.iterator(); iter
				.hasNext();) {
			iter.next().onAllianceMemberRoleChanged(source, target, allianceMember, changedType);
		}
	}
}
